<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
      
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo" label="订单号">
          <a-input placeholder="请输入订单号" disabled v-model="model.orderNo" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="meetingNum" label="会议号">
          <a-input placeholder="请输入会议号"  v-model="model.meetingNum" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderAmount" label="会议开始时间">
          <a-date-picker
                format="YYYY-MM-DD HH:mm:ss"
                :disabled-date="disabledDate"
                 show-time
				 placeholder="会议时间"
				 @change="changeTime"
              />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { postAction } from '@/api/manage'
  import moment from "moment"
  export default {
    name: "InterviewModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        },
		interviewDate: '',
		beginTime: '',
		endTime: '',
        url: {
          inviteInterview: "/wechat/wechatInterview/createInter"
        },
      }
    },
    created () {
    },
    methods: {
	  changeTime (date, datestring) {
	   let startTime =  datestring
	   this.interviewDate = startTime.split(' ')[0]
	   this.beginTime = startTime.split(' ')[1]
	  },
	  disabledDate(current) {
	        // Can not select days before today and today
	        return current && current < moment().subtract(1, 'day');
	   },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
         this.$refs.form.validate(valid => {
          if (valid) {
			let param = {
				interviewDate: this.interviewDate,
				orderId: this.model.id,
				demandId: this.model.demandId,
				beginTime: this.beginTime,
				meetingNum: this.model.meetingNum
			}
            that.confirmLoading = true;
            postAction(this.url.inviteInterview,param).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>